<script setup>
import { ref } from "vue";
import dayjs from "dayjs";
import axios from "axios";

defineProps({
  msg: String,
});

const count = ref(0);
let localTime = ref("");
let serviceTime = ref("");
function testLocalTime() {
  localTime.value = dayjs().format("YYYY-MM-DD HH:mm:ss");
}
function testLocalService() {
  axios
    .get("https://localhost:7233/getTime")
    .then(function (response) {
      // handle success
      serviceTime.value = response.data;
    })
    .catch(function (error) {
      // handle error
      console.log(error);
    })
    .finally(function () {
      // always executed
    });
}
</script>

<template>
  <h1>{{ msg }}</h1>

  <div>
    <button type="button" @click="testLocalTime">
      刷新本地时间 {{ localTime }}
    </button>
  </div>
  <div>
    <button type="button" @click="testLocalService">
      访问本地后台接口 {{ serviceTime }}
    </button>
  </div>
</template>

<style scoped>
.read-the-docs {
  color: #888;
}
</style>
